<?php
namespace App\Http\Controllers\Home;
use Illuminate\Http\Request;
use App\Models\Bmi;
use App\Http\Controllers\BaseController;
class BmiController extends BaseController
{
    public function userBmi(Request $requst)
    {
        $userId = $requst->get('userId');
        $bmiModel = new Bmi();

        if ($userId)
        {
            $bmiInfo = $bmiModel->selectMainBmi($userId);
            return $this->success($bmiInfo);
        }else
        {
            return $this->error('userId为空');
        }

    }
    public  function updataBmi(Request $request)
    {
        $userId = $request->get('userId');
        $data =
            [
                'name' => $request->get('name'),
                'age' => $request->get('age')
            ];
        if (!isset($data['name']))
        {
            return $this->error('name为空');
        }
        if (!isset($data['age']))
        {
            return $this->error('age为空');
        }
        if ($userId)
        {
            $bmiModel = new Bmi();
            $info = $bmiModel->updataBmi($data,$userId);
            if ($info)
            {
                return $this->success('','修改成功');
            }else
            {
                return $this->success('','修改失败');
            }
        }else
        {
            return $this->error('userid为空');
        }
    }
}